// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   OtherPanel.java

package com.boci.clientapp.holding.ui.control;

import com.boci.clientapp.holding.constant.HoldingConst;
import com.boci.clientapp.holding.vo.HoldingDetailVO;
import com.boci.clientapp.holding.vo.HoldingVO;
import com.boci.clientapp.main.ClientAppLoader;
import com.boci.common.constant.ClientAppConst;
import com.boci.common.ui.control.*;
import com.boci.common.util.MessagesConfigurator;
import com.boci.common.util.StringUtil;
import com.boci.common.vo.ResponseVO;
import java.awt.*;
import java.util.ArrayList;
import java.util.Locale;
import javax.swing.*;
import javax.swing.border.EtchedBorder;
import javax.swing.table.*;

// Referenced classes of package com.boci.clientapp.holding.ui.control:
//            TradeRenderer, TradeEditor

public class OtherPanel extends JPanel
{

    public OtherPanel(Locale pLocale)
    {
        msgConf = ClientAppLoader.getMessagesConfigurator();
        initGUI(pLocale);
        setText(pLocale);
    }

    private void initGUI(Locale pLocale)
    {
        titlePanel = new JPanel();
        otherSclPane = new JScrollPane();
        tblOther = new JTable();
        tmOther = new CMTableModel();
        tradeRenderer = new TradeRenderer(true, pLocale);
        tradeEditor = new TradeEditor(true, pLocale);
        nameRenderer = new NameRenderer(pLocale);
        ccyRenderer = new NameRenderer(pLocale);
        codeRenderer = new StringRenderer();
        stringRenderer = new StringRenderer();
        numericRenderer = new StringRenderer();
        codeRenderer.setHorizontalAlignment(0);
        numericRenderer.setHorizontalAlignment(4);
        ccyRenderer.setHorizontalAlignment(0);
        tblOther.setModel(tmOther);
        tblOther.getTableHeader().setReorderingAllowed(false);
        tblOther.setSelectionMode(1);
        tblOther.setCellSelectionEnabled(false);
        otherSclPane.setViewportView(tblOther);
        otherSclPane.getViewport().setOpaque(false);
        otherSclPane.setBorder(new EtchedBorder(1));
        otherSclPane.setOpaque(false);
        lblOtherTitle = new JLabel();
        titlePanel.setLayout(new FlowLayout(0));
        titlePanel.setOpaque(false);
        titlePanel.add(lblOtherTitle);
        titlePanel.setPreferredSize(new Dimension(0, 25));
        setLayout(new BorderLayout());
        setOpaque(false);
        add(titlePanel, "North");
        add(otherSclPane, "Center");
        setTableHeight();
    }

    private void setFont(Locale pLocale)
    {
        lblOtherTitle.setFont(ClientAppLoader.getSmallBoldTextFont(pLocale));
        tblOther.getTableHeader().setFont(ClientAppLoader.getSmallPlainTextFont(pLocale));
        stringRenderer.setFont(ClientAppLoader.getSmallPlainTextFont(pLocale));
        numericRenderer.setFont(ClientAppLoader.getSmallPlainTextFont(pLocale));
        codeRenderer.setFont(ClientAppLoader.getSmallPlainTextFont(pLocale));
    }

    public void setText(Locale pLocale)
    {
        tradeRenderer.setText(pLocale);
        tradeEditor.setText(pLocale);
        nameRenderer.setText(pLocale);
        ccyRenderer.setText(pLocale);
        lblOtherTitle.setText(msgConf.getUIMessages("HOLDING.OTHERS", pLocale));
        setFont(pLocale);
        String strUSOptionColName[] = {
            msgConf.getUIMessages("HOLDING.COL_NAME", pLocale), msgConf.getUIMessages("HOLDING.COL_CODE", pLocale), msgConf.getUIMessages("HOLDING.COL_CCY", pLocale), msgConf.getUIMessages("HOLDING.COL_QTY", pLocale), msgConf.getUIMessages("HOLDING.COL_PRICE", pLocale), msgConf.getUIMessages("HOLDING.COL_MARKET_VALUE", pLocale)
        };
        tmOther.setColumnName(strUSOptionColName);
        tmOther.fireTableStructureChanged();
        for(int i = 0; i < tblOther.getColumnCount(); i++)
        {
            TableColumn column = tblOther.getColumnModel().getColumn(i);
            if(i == 0)
                column.setCellRenderer(nameRenderer);
            else
            if(i == 1)
                column.setCellRenderer(codeRenderer);
            else
            if(i == 2)
                column.setCellRenderer(ccyRenderer);
            else
            if(i == 3 || i == 4 || i == 5)
                column.setCellRenderer(numericRenderer);
            else
                column.setCellRenderer(stringRenderer);
            column.setPreferredWidth(HoldingConst.COL_WIDTH_HOLDING_OTHER[i]);
        }

    }

    public void refresh(ResponseVO pResponseVO)
    {
        if(pResponseVO == null)
        {
            Object strTableData[][] = new Object[0][7];
            tmOther.setData(strTableData);
            tmOther.fireTableDataChanged();
            otherSclPane.getViewport().setViewPosition(new Point(0, 0));
            setTableHeight();
        } else
        if(pResponseVO instanceof HoldingVO)
        {
            HoldingVO holdingVO = (HoldingVO)pResponseVO;
            holdingDetailVOList = holdingVO.getOtherList();
            Object strTableData[][] = new Object[holdingDetailVOList.size()][7];
            for(int i = 0; i < holdingDetailVOList.size(); i++)
            {
                HoldingDetailVO holdingDetailVO = (HoldingDetailVO)holdingDetailVOList.get(i);
                String strName[] = {
                    holdingDetailVO.getStockName(), holdingDetailVO.getStockNameChi(), holdingDetailVO.getStockNameChs()
                };
                String strCur[] = {
                    msgConf.getUIMessages(holdingDetailVO.getCurrency(), ClientAppConst.EN_US), msgConf.getUIMessages(holdingDetailVO.getCurrency(), ClientAppConst.ZH_HK), msgConf.getUIMessages(holdingDetailVO.getCurrency(), ClientAppConst.ZH_CN)
                };
                strTableData[i][0] = strName;
                strTableData[i][1] = holdingDetailVO.getSymbol();
                strTableData[i][2] = strCur;
                String strQty = StringUtil.formatQtyValue(holdingDetailVO.getQuantity());
                String strPrice = StringUtil.formatPriceValue(holdingDetailVO.getPrice());
                String strMktValue = StringUtil.formatPriceValue(holdingDetailVO.getMarketValue());
                strTableData[i][3] = strQty;
                strTableData[i][4] = strPrice;
                strTableData[i][5] = strMktValue;
            }

            tmOther.setData(strTableData);
            tmOther.fireTableDataChanged();
            otherSclPane.getViewport().setViewPosition(new Point(0, 0));
            setTableHeight();
        }
    }

    public void setTableHeight()
    {
        int intTableHeight = tblOther.getRowHeight() * 6 + tblOther.getTableHeader().getPreferredSize().height + 4;
        otherSclPane.setPreferredSize(new Dimension(0, intTableHeight));
        otherSclPane.setMinimumSize(new Dimension(0, intTableHeight));
    }

    private JPanel titlePanel;
    private JTable tblOther;
    private CMTableModel tmOther;
    private JScrollPane otherSclPane;
    private JLabel lblOtherTitle;
    private TradeRenderer tradeRenderer;
    private TradeEditor tradeEditor;
    private NameRenderer nameRenderer;
    private NameRenderer ccyRenderer;
    private StringRenderer codeRenderer;
    private StringRenderer stringRenderer;
    private StringRenderer numericRenderer;
    private ArrayList holdingDetailVOList;
    private MessagesConfigurator msgConf;
}
